package Tests;

import static org.junit.Assert.*;

import org.junit.Test;

import Accounts.CheckingAccount;

public class CheckingAccountTest 
{
	private CheckingAccount chAccount;
	public CheckingAccountTest()
	{
		testCheckingAccountString();
		testCheckingAccountFloat();
		testCheckingAccountInt();
		testDetermineCosts();
		testWithdrawal();
		testVerseMoney();
		testApplyForCreditCard();
		testIncreaseBalance();
		testDecreaseBalance();
		testGetDebitAmount();
		testSetBalance();
		testGetAccountNumber();
		testEquals();
		testPrint();
	}
	@Test
	public void testCheckingAccountString()
	{
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA");
		assertNotNull("The newAccount object is null", newAccount);
	}

	@Test
	public void testCheckingAccountFloat()
	{
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA",0.001f);
		assertNotNull("The newAccount object is null", newAccount);
	}

	@Test
	public void testCheckingAccountInt()
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		assertNotNull("The newAccount object is null", newAccount);
	}

	@Test
	public void testDetermineCosts() 
	{
		CheckingAccount newAccount = new CheckingAccount(2);
		
		newAccount.determineCosts();
		System.out.println("cost: "+newAccount.getBalance());
	}

	

	
	@Test
	public void testWithdrawal() 
	{
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA", 100);
		double balance = newAccount.getBalance();//balance is 0
		double debitAmmount = newAccount.getDebitAmount();//debit amount is 100
		//withdrawing should return false, since balance is 0.
		assertFalse("Your balance is zero!", newAccount.withdrawal(1));
		assertEquals("Expected balannce vs actual balance",0.0, balance,0);
		
		//withdrawing should return True since (fBalance - amount) < -fDebitAmount
		assertTrue("(fBalance - amount) < -fDebitAmount!", newAccount.withdrawal(200));
		
	}

	@Test
	public void testVerseMoney() 
	{
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA");
		//add $3.00 to your account, the original balance was 0
		//New balance after the deposit should be 0 + 3 = 3.00.
		newAccount.verseMoney(3);
		double balance = newAccount.getBalance();
		assertEquals("Expected balannce vs actual balance",3, balance,0);
	}

	@Test
	public void testApplyForCreditCard() 
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		newAccount.decreaseBalance(100);//
		double balance = newAccount.getBalance();//balance is -100
		boolean creditCardRequest = newAccount.applyForCreditCard("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA", 1);
		assertFalse("Not qualified for Credit Card!", creditCardRequest);
		//add 200 to your account, the original balance was 0
		//New balance after the deposit should be -100 + 200 = 100.00.
		newAccount.verseMoney(200);
		System.out.println("balance: "+balance);
		balance = newAccount.getBalance(); //balance = -100+200 = 100
		System.out.println("balance: "+balance);
		creditCardRequest = newAccount.applyForCreditCard("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA", 1);
		assertTrue("should qulify for Credit Card!", creditCardRequest);
		newAccount.verseMoney(2500);
		balance = newAccount.getBalance(); //balance = 100+2500 = 2600
		creditCardRequest = newAccount.applyForCreditCard("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA", 1);

		assertTrue("should qualify for Credit Card!", creditCardRequest);
	}

	@Test
	public void testIncreaseBalance() 
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		//add 200 to your account, the original balance was 0
		//New balance after the deposit should be 0 + 200 = 200.00.
		newAccount.increaseBalance(200);
		double balance = newAccount.getBalance();
		assertEquals("Expected balannce vs actual balance",200, balance,0);

	}

	@Test
	public void testDecreaseBalance() 
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		//add 200 to your account, the original balance was 0
		//New balance after the deposit should be 0 + 200 = 200.00.
		newAccount.increaseBalance(200);
		//Decrease balance by $50.00. New balance should be $150.00.
		newAccount.decreaseBalance(50);
		double balance = newAccount.getBalance();
		assertEquals("Expected balannce vs actual balance",150, balance,0);
	}

	@Test
	public void testGetDebitAmount()
	{
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA",1000.00f);
		//debit amount should be $1000.00 since we are initializing it with $1000.00.
		double debit = newAccount.getDebitAmount();
		assertEquals("Expected debit vs actual debit",1000, debit,0);
	}

	@Test
	public void testSetBalance() 
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		//Set the balance to 200, the original balance was 0
		//New balance after setting the balance should be  200.00.
		newAccount.setBalance(200);
		
		double balance = newAccount.getBalance();
		assertEquals("Expected balannce vs actual balance",200, balance,0);
	}

	@Test
	public void testGetAccountNumber()
	{
		CheckingAccount newAccount = new CheckingAccount(1);
		//Since we are passing 1 as an account number when we create 
		//a new account, account number should be 1. 
		double accNum = newAccount.getAccountNumber();
		assertEquals("Expected accNumber vs actual accNumber",1,accNum,0);
	}

	@Test
	public void testEquals() 
	{
		CheckingAccount acc1 = new CheckingAccount(1);
		CheckingAccount acc2 = new CheckingAccount(1);
		//Since both acc1 and acc2 have the same account number, 
		//equals() method should return true.
		boolean areEqual = acc1.equals(acc2);
		assertTrue("The two objects are not equal", areEqual);
	}
	@Test 
	public void testPrint()
	{
		//Test the print method in checking account
		CheckingAccount newAccount = new CheckingAccount("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA",1000.00f);
		newAccount.print();	
		assertTrue(true);
		
	}

}
